/*
 * Copyright (c) 2001 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 *    David Corbin  - added default constructor that uses "self-constructed" status
 * 					- changed status to protected so derived classes can access it.
 */
package net.sourceforge.p4eclipse.core.api;

import java.util.Map;

import net.sourceforge.p4eclipse.ui.PerforceUIPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;


/**
  * @version	1.0
  * @author 	<a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  * @author		<a href="mailto:dcorbin@users.sourceforge.net">David Corbin</a>
  */
public class ClientUser implements IClientUser
{
	/* DON'T TOUCH THE CONTENT OF THIS VARIABLE */
	private int _nativeHandle;
	protected MultiStatus status;
	
	/**
	  * Creates a new ClientUser object.
	  */
	public ClientUser()
	{
		this(new MultiStatus(PerforceUIPlugin.ID, IStatus.OK, "", null));
	}
	public ClientUser(MultiStatus status)
	{
		construct();		
		this.status = status;
	}
	
	/**
	  * Make sure that native resources a freed.
	  */
	public void finalize() 
		throws Throwable
	{
		super.finalize();
		destruct();
	}

	public String inputData()
	{
		throw new UnsupportedOperationException();
	}
	
	public void outputError(String errorString)
	{
		status.merge(PerforceStatus.decode(errorString, IStatus.ERROR));
	}

	public void outputInfo(char level, String infoString)
	{
		status.merge(PerforceStatus.decode(infoString, IStatus.INFO));
	}

	public void outputText(String textString)
	{
		throw new UnsupportedOperationException();
	}

	public void outputStat(Map strDict)
	{
		throw new UnsupportedOperationException();
	}

	public void handleError(PerforceError error)
	{
		superHandleError(error);
	}

	public void message(PerforceError error)
	{
		superMessage(error);
	}

	public void resolve(ClientMerge clientMerge)
	{		
		throw new UnsupportedOperationException();		
	}
	
	public String prompt(String msg, boolean noEcho, PerforceError error)
	{
		//throw new UnsupportedOperationException();
		return "s";
	}

	private native void superHandleError(PerforceError error);
	private native void superMessage(PerforceError error);

	private native void construct();	
	private native void destruct();
}

